package org.microframework.cloud.logs.controller;

import org.microframework.base.core.domain.R;
import org.microframework.cloud.logs.model.dto.StatisticsDTO;
import org.microframework.cloud.logs.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 日志统计分析控制器
 *
 * @author zs
 * @version 1.0.0
 * @since 2024-06-14
 */
@RestController
@RequestMapping("/statistics")
@Tag(name = "日志统计", description = "日志统计分析接口")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 获取登录统计数据
     */
    @GetMapping("/login")
    @Operation(summary = "获取登录统计数据", description = "获取指定天数内的登录统计数据")
    public R<StatisticsDTO> getLoginStatistics(
            @Parameter(description = "统计天数，默认7天") @RequestParam(defaultValue = "7") Integer days) {
        return R.ok(statisticsService.getLoginStatistics(days));
    }

    /**
     * 获取操作日志统计数据
     */
    @GetMapping("/operation")
    @Operation(summary = "获取操作日志统计数据", description = "获取指定天数内的操作日志统计数据")
    public R<StatisticsDTO> getOperationStatistics(
            @Parameter(description = "统计天数，默认7天") @RequestParam(defaultValue = "7") Integer days) {
        return R.ok(statisticsService.getOperationStatistics(days));
    }

    /**
     * 获取系统日志统计数据
     */
    @GetMapping("/system")
    @Operation(summary = "获取系统日志统计数据", description = "获取指定天数内的系统日志统计数据")
    public R<StatisticsDTO> getSystemStatistics(
            @Parameter(description = "统计天数，默认7天") @RequestParam(defaultValue = "7") Integer days) {
        return R.ok(statisticsService.getSystemStatistics(days));
    }

    /**
     * 获取API调用统计数据
     */
    @GetMapping("/api")
    @Operation(summary = "获取API调用统计数据", description = "获取指定天数内的API调用统计数据")
    public R<StatisticsDTO> getApiStatistics(
            @Parameter(description = "统计天数，默认7天") @RequestParam(defaultValue = "7") Integer days) {
        return R.ok(statisticsService.getApiStatistics(days));
    }

    /**
     * 获取异常日志统计数据
     */
    @GetMapping("/error")
    @Operation(summary = "获取异常日志统计数据", description = "获取指定天数内的异常日志统计数据")
    public R<StatisticsDTO> getErrorStatistics(
            @Parameter(description = "统计天数，默认7天") @RequestParam(defaultValue = "7") Integer days) {
        return R.ok(statisticsService.getErrorStatistics(days));
    }

    /**
     * 获取综合统计看板数据
     */
    @GetMapping("/dashboard")
    @Operation(summary = "获取综合统计看板数据", description = "获取系统综合统计看板数据")
    public R<StatisticsDTO> getDashboardData() {
        return R.ok(statisticsService.getDashboardData());
    }

    /**
     * 获取用户活跃度分析数据
     */
    @GetMapping("/user-activity")
    @Operation(summary = "获取用户活跃度分析数据", description = "获取指定天数内的用户活跃度分析数据")
    public R<StatisticsDTO> getUserActivityData(
            @Parameter(description = "统计天数，默认30天") @RequestParam(defaultValue = "30") Integer days) {
        return R.ok(statisticsService.getUserActivityData(days));
    }
} 